package com.dfbz.utils;

import com.dfbz.constant.Const;

public class PageUtil {

    public static long getTotalPage(long totalCount) {
        return totalCount % Const.MAX_PAGE_SIZE == 0 ? totalCount / Const.MAX_PAGE_SIZE : totalCount / Const.MAX_PAGE_SIZE + 1;
    }

    public static long getStartPage(long currentPage) {
        long start = currentPage % Const.PAGE_COUNT == 0 ? currentPage / Const.PAGE_COUNT : currentPage / Const.PAGE_COUNT + 1;
        return (start - 1) * Const.PAGE_COUNT;
    }

    public static long getEndPage(long currentPage, long totalPage) {
        long startPage = getStartPage(currentPage);
        if (startPage + Const.PAGE_COUNT <= totalPage) {
            return startPage + Const.PAGE_COUNT;
        } else {
            return totalPage;
        }
    }

}
